1
2 Imports System.Data.SqlClient
3 Imports System.Security.Cryptography
4 Imports System.IO
5 Imports System.Text
6 Imports System.Collections.Generic
7 Module ModFunc
8     Sub LogFunc(ByVal st1 As String, ByVal st2 As String)
9         con = New SqlConnection(cs)
10         con.Open()
11         Dim cb As String =
"insert into Logs(UserID,Date,Operation) VALUES (@d1,@d2,@d3)"
12         cmd = New SqlCommand(cb)
13         cmd.Connection = con
14         cmd.Parameters.AddWithValue(
"@d1", st1)
15         cmd.Parameters.AddWithValue(
"@d2", System.DateTime.Now)
16         cmd.Parameters.AddWithValue(
"@d3", st2)
17         cmd.ExecuteReader()
18         con.Close()
19     End Sub
20     Public Function Encrypt(password As String) As String
21         Dim strmsg As String = String.Empty
22         Dim encode As Byte() = New Byte(password.Length -
1) {}
23         encode = Encoding.UTF8.GetBytes(password)
24         strmsg = Convert.ToBase64String(encode)
25         Return strmsg
26     End Function
27
28     Public Function Decrypt(encryptpwd As String) As String
29         Dim decryptpwd As String = String.Empty
30         Dim encodepwd As New UTF8Encoding()
31         Dim Decode As Decoder = encodepwd.GetDecoder()
32         Dim todecode_byte As Byte() = Convert.FromBase64String(encryptpwd)
33         Dim charCount As Integer = Decode.GetCharCount(todecode_byte,
0, todecode_byte.Length)
34         Dim decoded_char As Char() = New Char(charCount -
1) {}
35         Decode.GetChars(todecode_byte,
0, todecode_byte.Length, decoded_char, 0)
36         decryptpwd = New [String](decoded_char)
37         Return decryptpwd
38     End Function
39 End Module


Gõ tìm kiếm nhanh...